import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart' as http;

//异步函数 两种方式 
//1. then
// Future getIpAddress(){
//   final url = 'https://httpbin.org/ip';
//   return http.get(url).then((response) {
//     String ip = jsonDecode(response.body)['origin'];
//     return ip;
//   });
// }

//2. async
Future getIpAddress() async {
  final url = 'https://httpbin.org/ip';
  final response = await http.get(url);
  String ip = jsonDecode(response.body)['origin'];
  return ip;
}
 
void main() async {
  // getIpAddress()
  // .then((ip) => print(ip))
  // .catchError((error) => print(error));
   String ip = await getIpAddress();
   print('ip = $ip');
}

